package edu.nanyang.controller;

import edu.nanyang.domain.AdminInfo;
import edu.nanyang.service.AdminInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class AdminLoginController extends BaseController{
    @Resource
    private AdminInfoService adminInfoService;
    @PostMapping("/adminlogin")
    public String adminLogin(String adminName,String adminPass){
        AdminInfo adminInfo= adminInfoService.getByNameAndPass(adminName,adminPass);
        if(adminInfo!=null){
            HttpSession session=request.getSession();
            session.setAttribute("login_admin",adminInfo);
            return "index";
        }else{
            request.setAttribute("tip_info","用户名和密码错误");
            return "admin_login";
        }
    }

    @GetMapping("adminlogout")
    public String adminLogout(){
        //session失效
        request.getSession().invalidate();
        return "admin_login";
    }
}
